<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>My JSP 'editSysResource.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<link href="${ctx }/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
<link href="${ctx }/css/font-awesome.css?v=4.4.0" rel="stylesheet">
<link href="${ctx }/css/plugins/multiselect/bootstrap-multiselect.css"
	rel="stylesheet">
<!-- jqgrid-->
<link href="${ctx }/css/plugins/jqgrid/ui.jqgrid.css?0820"
	rel="stylesheet">
<link href="${ctx }/css/animate.css" rel="stylesheet">
<link href="${ctx }/css/style.css?v=4.1.0" rel="stylesheet">
<!-- zTree -->
<link href="${ctx }/css/plugins/zTreeStyle/metro.css" rel="stylesheet">
<!--bootstrap-select-->
<link
	href="${ctx}/css/plugins/bootstrap-select/bootstrap-select.min.css"
	rel="stylesheet" />
<style type="text/css">
body {
	background: none;
}
#xz #treeDemo {
	border: 1px solid black;
	margin-top: 0;
	width: 100%;
	height: 200px;
	position: absolute;
	background: #fff;
	overflow: auto;
	z-index: 100;
}
</style>
</head>
<div class="inmodal" role="dialog" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content animated bounceInRight">
			<div class="modal-header">
				<button type="button" class="close closeWin" data-dismiss="modal">
					<span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
				</button>
				<h4 class="modal-title">修改用户</h4>
			</div>
			<div class="ibox-content">
				<form class="form-horizontal m-t" id="editSysUserForm">
					<input id="id" name="id" type="hidden" value="${sysUser.id }">
					<input id="userId" name="userId" type="hidden"
						value="${sysUser.id }">
					<div class="form-group">
						<label class="col-sm-3 control-label">员工ID:</label>
						<div class="col-sm-8">
							<input id="emp_id" name="emp_id" class="form-control" required=""
								aria-required="ture" type="text" placeholder="请输入员工ID"
								value="${sysUser.sysUserInfo.emp_id}" readonly="readonly">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">成员姓名:</label>
						<div class="col-sm-8">
							<input id="emp_name" name="emp_name" class="form-control"
								required="" aria-required="ture" disabled="disabled" type="text"
								placeholder="" value="${sysUser.sysUserInfo.emp_name}">
						</div>
					</div>

					<div class="form-group">
						<label class="col-sm-3 control-label">所属部门:</label>
						<div class="col-sm-8">
							<input id="orgName" name="orgName" class="form-control"
								required="" aria-required="true" disabled="disabled" type="text"
								placeholder="" value="${sysUser.sysOrgInfo[0].org_name }">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">机构范围:</label>
						<div class="col-sm-6">
							<input id="org_id" name="org_id" type="hidden" value="${sysUser.sysUserPermission.org_id}"> <input
								id="org_name" name="org_name" class="form-control" required=""
								aria-required="true" type="text" readOnly="true" value="${sysUser.sysUserPermission.org_name}"> <span
								class="help-block m-b-none" style="color: red; display:none;">请选择机构！</span>
							<div  id="xz" style="position: relative;left:0;">
								<input type="hidden" id="show_user" name="show_user">
								<ul id="treeDemo" class="ztree" ></ul>
							</div>
						</div>
						<button type="button" class="btn btn-success btn-outline"
							id="SysUserOrg"
							onClick="getUserNode('${sysUser.sysUserPermission.org_id}');">
							<i class="fa fa-plus"></i>请选择
						</button>
						
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">所属角色:</label>
						<div class="col-sm-8">
							<select class="selectpicker" required="" aria-required="true"
								name="roleId" id="roleId">
								<option value="">--请选择--</option>
								<c:forEach items="${roleList}" var="roleInfo">
									<option value="${roleInfo.id}"
										<c:if test="${roleId==roleInfo.id }">selected</c:if>>${roleInfo.name}</option>
								</c:forEach>
							</select>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">系统账号:</label>
						<div class="col-sm-8">
							<input id="userName" name="userName" class="form-control"
								required="" aria-required="ture" type="text"
								placeholder="请输入账号名" value="${sysUser.userName }"
								readonly="readonly">
						</div>
					</div>

					<div class="form-group">
						<label class="col-sm-3 control-label">账户说明:</label>
						<div class="col-sm-8">
							<input id="description" name="description" class="form-control"
								required="" aria-required="true" type="text"
								placeholder="请输入账户说明" value="${sysUser.description }">
						</div>
					</div>

					<div class="form-group">
						<div class="col-sm-8 col-sm-offset-5" style="height:60px">
							<button type="button" class="btn btn-white closeWin"
								id="closeWin">关闭</button>
							<button type="submit" class="btn btn-primary">保存</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
<!-- 全局js -->
<script src="${ctx }/js/jquery.min.js?v=2.1.4"></script>
<script src="${ctx }/js/bootstrap.min.js?v=3.3.6"></script>
<script src="${ctx }/js/plugins/multiselect/bootstrap-multiselect.js"></script>
<!-- Peity -->
<script src="${ctx }/js/plugins/peity/jquery.peity.min.js"></script>

<!-- jqGrid -->
<script src="${ctx }/js/plugins/jqgrid/i18n/grid.locale-cn.js?0820"></script>
<script src="${ctx }/js/plugins/jqgrid/jquery.jqGrid.min.js?0820"></script>

<!-- jQuery Validation plugin javascript-->
<script src="${ctx }/js/plugins/validate/jquery.validate.min.js"></script>
<script src="${ctx }/js/plugins/validate/messages_zh.min.js"></script>

<!-- layer javascript -->
<script src="${ctx }/js/plugins/layer/layer.min.js"></script>

<!-- jQuery form-->
<script src="${ctx }/js/jquery.form.js"></script>

<!-- 自定义js -->
<script src="${ctx }/js/content.js?v=1.0.0"></script>
<!-- ztree plugin javascript -->
<script src="${ctx }/js/plugins/zTree/jquery.ztree.core.min.js"></script>
<script src="${ctx }/js/plugins/zTree/jquery.ztree.exhide.min.js"></script>
<script src="${ctx }/js/plugins/zTree/jquery.ztree.exedit.min.js"></script>
<script src="${ctx }/js/plugins/zTree/jquery.ztree.excheck.min.js"></script>
<!--bootstrap-select-->
<script src="${ctx}/js/plugins/bootstrap-select/bootstrap-select.min.js"></script>
<script type="text/javascript">
	$('#example-multiple-selected').multiselect({
		buttonWidth : '100%'
	});
	var v_user_id = ${sysUser.id};
	$(document).ready(function() {
		orgTreeload();
		$.jgrid.defaults.styleUI = 'Bootstrap';
		//绑定修改表单提交事件,异步提交表单
		$('#editSysUserForm').submit(function() {

			$.ajax({
				type : "post",
				url : "${ctx }/security/user/doEditSysUser",
				data : $('#editSysUserForm').serialize(),
				success : function(data) {
					if (data.errcode == 0) {
						layer.alert(data.errmsg, {
							icon : 1
						}, function(index) {
							//刷新表格数据
							window.parent.editWinClose('0');
							//关闭提示框
							layer.close(index);
						});
					} else if (data.errcode == 1) {
						layer.alert(data.errmsg, {
							icon : 2
						});
					}
					;
				},
				error : function() {
					layer.alert('修改用户数据异常！', {
						icon : 2
					});
				}
			});
			return false;
		});

		$('.closeWin').click(function() {
			window.parent.editWinClose('1');
		});

	});

	//-------选择机构树加载 START--------//
	var treeUser;
	var v_node_id;
	var setting = {
		check : {
			enable : true,
			chkStyle : "radio",
			radioType : "all"
		},
		data : {
			simpleData : {
				enable : true,
				idKey : "id",
				pIdKey : "pId"
			}
		},
		async : {
			enable : true,
			url : "${ctx}/orgTree/getOrgJson?user_id=" + v_user_id,
			autoParam : [ "id", "name" ]
		},
		callback : {
			onCheck : zTreeOnCheck,
			onExpand : zTreeOnExpand,
			onAsyncSuccess : onAsyncSuccess_org
		//异步加载成功后执行的方法
		}
	};
	//初始化加载选择机构树
	function orgTreeload() {
		$('#xz').hide();
		$.fn.zTree.init($("#treeDemo"), setting);
		treeUser = $.fn.zTree.getZTreeObj("treeDemo");
	}
	//节点展开触发
	function zTreeOnExpand(event, treeId, treeNode) {
		//alert(treeNode.id + ", " + treeNode.name+"--"+v_node_id);
		var v_child_node = treeNode.children;
		for ( var j = 0; j < v_child_node.length; j++) {
			//alert("v_child_node-"+v_child_node[j].id+","+v_node_id);
			if (v_child_node[j].id == v_node_id) {
				treeUser.checkNode(v_child_node[j], true);

			}
			;
		}
		;
	};
	//选择节点触发
	function zTreeOnCheck(event, treeId, treeNode) {
		var nodes = treeUser.getCheckedNodes(true);
		if (nodes.length > 0) {
			$('#org_id').val(treeNode.id);
			$('#org_name').val(treeNode.name);
		} else {
			$('#org_id').val("");
			$('#org_name').val("");
		}
		$("#show_user").val("");
		$('#xz').hide();
	};

	function onAsyncSuccess_org() {
		var nodes = treeUser.getCheckedNodes(true);
		if (nodes.length > 0) {
			$('#org_name').val(nodes[0].name);
			$('#org_id').val(nodes[0].id);
		}
	}

	//点击请选择，选择用户-层显示控制
	function sysuser() {
		var v_show_user = $("#show_user").val();
		if (v_show_user == "") {
			$("#show_user").val("0");
			$('#emp_name').next().hide();
			$('#xz').show();
		} else {
			$('#xz').hide();
			$("#show_user").val("");
		}
		;
	}
	//点击按钮触发-选择用户操作
	function getUserNode(x) {
		sysuser();
		v_node_id = x;
	}

	//------------end--------------------//
</script>



</html>
